package com.aierkeji.b2c.utils;

import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;
import java.util.Map;
import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class StringUtils extends org.apache.commons.lang.StringUtils {

	public static boolean checkAnyNotNull(String...strings){
		for(String s:strings){
			if(isNotBlank(s)){
				return true;
			}
		}
		return false;
	}
	
	public static boolean checkAnyNull(String...strings){
		for(String s:strings){
			if(isBlank(s)){
				return true;
			}
		}
		return false;
	}
	
	public static boolean equalsAny(String str,String[] arr){
		for(String s:arr){
			if(equals(s, str)){
				return true;
			}
		}
		return false;
	}
	
	
	/**
	 * 获取当前时分秒
	 */
	public static String getTime(){
		Calendar ca = Calendar.getInstance();
		
		Integer hou = ca.get(Calendar.HOUR_OF_DAY);
		String hour = null;
		if(hou<=9){
			hour = "0"+String.valueOf(hou);//小时 
		}else{
			hour = String.valueOf(hou);
		}
		
		Integer min = ca.get(Calendar.MINUTE);
		String minute = null;
		if(min<=9){
			minute = "0"+String.valueOf(min);//分 
		}else{
			minute = String.valueOf(min);//分 
		}
		
		Integer sec = ca.get(Calendar.SECOND);
		String second = null;
		if(sec<=9){
			second = "0"+String.valueOf(sec);//秒
		}else{
			second = String.valueOf(sec);//秒
		}
		
		return hour+minute+second;
	}
	
	/**
	 * 生成随机数字字母符串
	 * @param length
	 * @return
	 */
    public static String getRandomStringByLength(int length) {  
        String base = "abcdefghijklmnopqrstuvwxyz0123456789";  
        Random random = new Random();  
        StringBuffer sb = new StringBuffer();  
        for (int i = 0; i < length; i++) {  
            int number = random.nextInt(base.length());  
            sb.append(base.charAt(number));  
        }  
        return sb.toString();  
    }
    
    /**
     * 生成随机数字字符串
     * @param length
     * @return
     */
    public static String getRandomFigureByLength(int length) {  
        String base = "0123456789";  
        Random random = new Random();  
        StringBuffer sb = new StringBuffer();  
        for (int i = 0; i < length; i++) {  
            int number = random.nextInt(base.length());  
            sb.append(base.charAt(number));  
        }  
        return sb.toString();  
    }
	
    /**
	 * 获取当前日期（年月日）
	 */
	public static String getDate(){
		SimpleDateFormat sdf  = new SimpleDateFormat("yyyyMMdd");
		return sdf.format(new Date());
	}
	public static String processTemplate(String template, Map<String, Object> params) {
		StringBuffer sb = new StringBuffer();
		Matcher m = Pattern.compile("\\$\\{\\w+\\}").matcher(template);
		while (m.find()) {
			String param = m.group();
			Object value = params.get(param.substring(2, param.length() - 1));
			m.appendReplacement(sb, value == null ? "" : value.toString());
		}
		m.appendTail(sb);
		return sb.toString();
	}
	
	
	
	
}
